<?php

namespace api\controller;

use common\controller\VerifyController;
use common\service\StepProjectService;
use think\Request;
use think\Response;

class StepProjectController extends VerifyController
{

    protected $stepProjectService;

    public function __construct()
    {
        parent::__construct();
        $this->stepProjectService = StepProjectService::getInstance();
    }

    /**
     * 项目级上下游组装限制配置
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function setSkipUpstream(Request $request)
    {
        $param = $request->param()['data'];
        $stepId = $param['step_id'];
        $projectId = $param['project_id'];
        $isSkipUpstream = $param['is_skip_upstream'];
        $res = $this->stepProjectService->setStepSkipUpstream($stepId, $projectId, $isSkipUpstream);
        return json(success_response('', $res));
    }

    /**
     * 设置配置
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function setData(Request $request)
    {
        $param = $request->param()['data'];
        $stepId = $param['step_id'];
        $projectId = $param['project_id'];
        $data = $param;
        $res = $this->stepProjectService->setData($stepId, $projectId, $data);
        return json(success_response('', $res));
    }

    /**
     * 查询配置
     * @param Request $request
     * @return Response
     */
    public function getData(Request $request){
        $param = $request->param()['param'];
        $stepId = $param['step_id'];
        $projectId = $param['project_id'];
        $res = $this->stepProjectService->getData($stepId, $projectId);
        return json(success_response('', $res));
    }

    /**
     * 获取项目工序组装限制状态
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function getSkipUpstreamStatus(Request $request)
    {
        $param = $request->param()['param'];
        $projectId = $param['project_id'];
        $res = $this->stepProjectService->getSkipUpstreamStatus($param, $projectId);
        return json(success_response('', $res));
    }
}
